new Handle:g_FakeBot = INVALID_HANDLE
new Handle:g_FakeBotName = INVALID_HANDLE
static PlaceHolder 

//--------------------------------------------//
// Here we are decide to spawn a BOT (YES/NO) //
//--------------------------------------------//
public SpawnBot(Handle:convar, const String:oldValue[], const String:newValue[])
{
	if (Synergy)
	{
		if (StringToInt(newValue) == 1)	
		{
			// Here we check if bot already spawned if not then we do
			if(!PlaceHolder || (!IsClientConnected(PlaceHolder) && !IsClientInGame(PlaceHolder)))
			{
				PlaceHolder = 0
				DO_CreateFakeClient()
			}
		}
		else
		{
			// Bot is already ingame and now we want to kick him
			if(IsInGame(PlaceHolder))
			{
				KickClient(PlaceHolder)
			}
		}
	}
	return
}

//------------------------------------------------//
// Do we need to switch Teams? maybe to Spectator //
//------------------------------------------------//
public Action:TeamSwitch(Handle:Timer, any:Client)
{
	if (!IsInGame(Client))
		return Plugin_Handled

	ChangeClientTeam(Client, 0)
	
	return Plugin_Handled
}

//------------------------------------------------------------------//
// Now we give BOT invulnerable to prevent Players/Clients kill him //
//------------------------------------------------------------------//
public Action:BotGod(Handle:Timer, any:Client)
{
	if (!IsInGame(Client))
		return Plugin_Handled

	// Godmode him
	SetEntProp(Client, Prop_Data, "m_takedamage", 0, 1)
	// Freeze him
	SetEntityMoveType(Client, MOVETYPE_NONE)
	// Set nice color to him
	SetEntityRenderColor(Client, 0, 128, 255, 192)
	
	return Plugin_Handled
}

//-----------------------------------------------//
// Here we are spawning the BOT ingame with name //
//-----------------------------------------------//
public Action:DO_CreateFakeClient()
{
	decl String:Name[32]
	GetConVarString(g_FakeBotName, Name, sizeof(Name))
	if(StrEqual(Name, "$null") || StrEqual(Name, ""))
	{
		PrintToServer("[SM] No name specified in config file.")
		return Plugin_Handled
	}
	// Here we actually really spawn the Bot ingame
	PlaceHolder = CreateFakeClient(Name)
	// switch teams
	CreateTimer(0.1, TeamSwitch, PlaceHolder)
	// invulnerable him
	CreateTimer(0.1, BotGod, PlaceHolder)
	return Plugin_Handled
}